<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">
        <!-- 用了一个行列布局 -->
        <TREE :node-data="company" :is-tree="true" @addDepartment="addDepartment" />
        <hr>
        <el-tree :data="depart" :props="psrt" :default-expand-all="true" :expand-on-click-node="false">
          <template #default="{data}">
            <TREE
              :node-data="data"
              :is-tree="false"
              @Department="Getdepartment"
              @addDepartment="addDepartment"
              @editDepartment="editDepartment"
            />
          </template>
        </el-tree>
      </el-card>
      <AddTree
        ref="addDept"
        :is-active.sync="isActive"
        :node-data="nodeData"
        @addDepartment="Getdepartment"
      />
    </div>
  </div>
</template>

<script>
import TREE from './components/tree.vue'
import AddTree from './components/addtree.vue'
import { Getdepartment } from '@/api/departments'
import { ListTree } from '@/utils/index'
export default {
  components: {
    TREE,
    AddTree
  },
  data() {
    return {
      company: { name: '江苏传智播客教育科技股份有限公司', manager: '负责人', id: '' },
      psrt: { label: 'name' },
      depart: [],
      isActive: false,
      nodeData: {}
    }
  },
  created() {
    this.Getdepartment()
  },
  methods: {
    async Getdepartment() {
      const { depts } = await Getdepartment()
      // console.log('1p1', depts)
      this.depart = ListTree(depts, '')
      // console.log(222, this.depart)
    },
    // ListTree(list, reqpid),
    addDepartment(nodeData) {
      this.nodeData = nodeData
      this.isActive = true
    },
    async editDepartment(nodeData) {
      await this.$refs.addDept.getDepartmentDetail(nodeData.id)
      this.nodeData = nodeData
      this.isActive = true
    }
  }
}
</script>

<style scoped>
.tree-card {
  padding: 30px  140px;
  font-size:14px;
}
.pose{
  cursor: pointer;
}
</style>
